package com.jike.noobmoney.mvp.view.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import com.jike.noobmoney.R;
import com.jike.noobmoney.adapter.ChannelsAdapter;
import com.jike.noobmoney.entity.MyTaskChannelEntity;
import com.jike.noobmoney.mvp.view.fragment.MyPushFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Create by xuke on 2019/02/28
 * 我的发布
 */
public class MyPushActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.channelTab)
    TabLayout channelTab;
    @BindView(R.id.viewpger)
    ViewPager viewpger;

    private List<MyTaskChannelEntity> tabNameList = new ArrayList<>();
    private List<Fragment> newsFragmentList = new ArrayList<>();

    @Override
    protected int layoutResID() {
        return R.layout.activity_my_task;
    }
    /**
     * 如果要全屏,重写这个方法返回false
     */
    public Boolean isfits() {
        return true;
    }

    /**
     * 如果要白色主题,重写这个方法返回false
     */
    public boolean ismain() {
        return true;
    }
    @Override
    protected void initData() {
        tvTitle.setText("悬赏管理");
        tabNameList.add(new MyTaskChannelEntity("上架中", "2"));
        tabNameList.add(new MyTaskChannelEntity("待上架", "1"));
        tabNameList.add(new MyTaskChannelEntity("上架失败", "3"));
        tabNameList.add(new MyTaskChannelEntity("下架中", "4"));
        tabNameList.add(new MyTaskChannelEntity("待结算", "5"));
        tabNameList.add(new MyTaskChannelEntity("已结算", "6"));

        for (int i = 0; i < tabNameList.size(); i++) {
            MyPushFragment newsListFragment = new MyPushFragment();
            Bundle bundle = new Bundle();
            bundle.putString(MyPushFragment.Channels, tabNameList.get(i).getStatus());
            newsListFragment.setArguments(bundle);
            newsFragmentList.add(newsListFragment);
            channelTab.addTab(channelTab.newTab().setText(tabNameList.get(i).getTitle()));
        }

        ChannelsAdapter adapter = new ChannelsAdapter(getSupportFragmentManager(), tabNameList, newsFragmentList);
        viewpger.setAdapter(adapter);
        channelTab.setupWithViewPager(viewpger);
        viewpger.setOffscreenPageLimit(tabNameList.size());

        viewpger.setCurrentItem(0);
    }


    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
